<?php
    function __autoload($class_name)
	{
		include_once('../classes/'.strtolower($class_name).'.php');
	}
    require 'define.php';
    require 'functions.php';
    
    $MaSanPham = $_POST['MaSanPham'];
    
    $sanpham = new sanphambs();
    $sanpham->MaSanPham = $MaSanPham;
    $ret_sanpham = $sanpham->getList();
    
    $HinhNho = explode('|', $ret_sanpham[0]['HinhNho']);
    $HinhTo = explode('|', $ret_sanpham[0]['HinhTo']);
    
    $Loi = false;
    
    foreach($HinhNho as $k=>$v)
    {
        if($v != "")
        {
            if(deleteFile($v, DIRSMALL))
            {
                
            }
            else
                $Loi = true;
        }
    }
    
    foreach($HinhTo as $k=>$v)
    {
        if($v != "")
        {
            if(deleteFile($v, DIRBIG))
            {
                
            }
            else
                $Loi = true;
        }
    }
    
    if($Loi == false)
    {
        if($sanpham->delete())
            echo "yes";
        else
            echo "no";
    }
    else
        echo "no";
?>